collection

hidden abstract type collection<T> : iterable<T>

A generic type for mutable ordered collections of elements. Subtype of iterable<T>. Supports many standard operations such add insertion, removal, lookup and sorting.

Since

0.6.0

Inheritors

Functions

Link copied to clipboard
function add(value: T): boolean

Append an element to the end of this collection.

The element is not added if this collection does not allow duplicates and the element is already contained in this collection.

Link copied to clipboard
function add_all(values: collection<-T>): boolean

Add all elements from another collection to the end of this collection.

If this collection does not allow duplicates, then only those elements not already contained in this collection are added.

Link copied to clipboard
(alias) function addAll(values: collection<-T>): boolean

Add all elements from another collection to the end of this collection.

If this collection does not allow duplicates, then only those elements not already contained in this collection are added.

Alias
Link copied to clipboard
function clear()

Clear this collection; i.e. remove all its elements. Immediately after this method returns, this collection is empty.

Link copied to clipboard
pure function contains(value: T): boolean

Check if this collection contains the given element.

Link copied to clipboard
pure function contains_all(values: collection<-T>): boolean

Check if this collection contains all elements of another collection.

Link copied to clipboard
(alias) pure function containsAll(values: collection<-T>): boolean

Check if this collection contains all elements of another collection.

Link copied to clipboard
pure function empty(): boolean

Check if this collection is empty.

Link copied to clipboard
pure function join_to_text([separator: text], [prefix: text], [postfix: text], [limit: integer?], [truncated: text], [transform: (T) -> text]): text

Generate a textual representation of this iterable.

An optional separator, prefix and postfix can be provided. One can also provide a limit: integer?. If there are more elements in the result than limit, the elements whose indices exceed limit are omitted, and the passed truncated: text is included instead.

Examples:

  • [1, 2, 3].join_to_text() returns '1, 2, 3'.

  • [1, 2, 3].join_to_text('_') returns '1_2_3'.

  • [1, 2, 3].join_to_text('*', '(', ')') returns '(1*2*3)'.

  • list<T>().join_to_text('!', '(', ')') returns '()' (where T is a valid type).

  • range(10).join_to_text('', '', '', 5) returns '01234...'.

  • range(10).join_to_text('', '', '', 5, 'more') returns '01234more'.

Where the function even is defined:

function even(x: integer): text {
return if (x % 2 == 0) 'EVEN' else 'ODD';
}

Then:

  • range(10).join_to_text('->', '{', '}', 5, '...', even(*)) returns {EVEN->ODD->EVEN->ODD->EVEN->...}.

Link copied to clipboard
(alias) pure function len(): integer

Get the size (number of elements) of this collection.

Alias
Link copied to clipboard
function remove(value: T): boolean

Remove an element from this collection.

Link copied to clipboard
function remove_all(values: collection<-T>): boolean

Remove all elements in another collection from this collection.

Link copied to clipboard
(alias) function removeAll(values: collection<-T>): boolean

Remove all elements in another collection from this collection.

Link copied to clipboard
pure function size(): integer

Get the size (number of elements) of this collection.

Link copied to clipboard
pure function sorted(): list<T>

Sorts the elements of this collection into a list. This collection is not modified.

Link copied to clipboard
(alias) pure function str(): text

Returns a textual representation of this collection.

Alias
Link copied to clipboard
pure function to_text(): text

Returns a textual representation of this collection.